package binarytree;

import java.util.LinkedList;
import java.util.Queue;

public class Test {
    public static void main(String[] args) {
        MyBinaryTree myBinaryTree = new MyBinaryTree();
        BTNode root = myBinaryTree.creationTree();
        System.out.print("前序遍历：");
        myBinaryTree.preorderTraversal(root);
        System.out.println();// 换行
        System.out.print("中序遍历：");
        myBinaryTree.inorderTraversal(root);
        System.out.println();// 换行
        System.out.print("后序遍历：");
        myBinaryTree.postorderTraversal(root);
        System.out.println();//换行
        System.out.print("节点个数：");
        System.out.println(myBinaryTree.size(root));
        System.out.println(myBinaryTree.size2(root));
        System.out.print("叶子结点个数：");
        System.out.print(myBinaryTree.getLeafNode(root));
        System.out.println();// 换行
        System.out.println(myBinaryTree.getLeafNode2(root));
        System.out.print("第K层节点个数：");
        System.out.println(myBinaryTree.getLevelNode(root, 3));
        System.out.print("二叉树的高度为：");
        System.out.println(myBinaryTree.getHeight(root));
        System.out.print("判断指定 H 值是否存在，存在返回其引用：");
        System.out.println(myBinaryTree.find(root,'D'));
        try {
            System.out.println(myBinaryTree.find(root, 'D').val);
        }catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("指定的元素不存在，造成空指针异常");
        }
        System.out.println(myBinaryTree.isCompleteTree(root));
        System.out.println();// 换行
        System.out.print("层次遍历：");
        myBinaryTree.levelTraversal(root);
    }
}
